package org.example.gift.controller;

import com.baomidou.mybatisplus.plugins.Page;
import org.example.gift.domain.UserGrowLog;
import org.example.gift.query.UserGrowLogQuery;
import org.example.gift.service.IUserGrowLogService;
import org.example.gift.util.AjaxResult;
import org.example.gift.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userGrowLog")
public class UserGrowLogController {
    @Autowired
    public IUserGrowLogService userGrowLogService;

    /**
     * 保存和修改公用的
     * @param userGrowLog  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody UserGrowLog userGrowLog){

        if( userGrowLog.getId()!=null)
            userGrowLogService.updateById(userGrowLog);
        else
            userGrowLogService.insert(userGrowLog);
        return AjaxResult.success();

    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        userGrowLogService.deleteById(id);
        return AjaxResult.success();

    }
	
    //获取用户
    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable("id")Long id)
    {

        UserGrowLog userGrowLog = userGrowLogService.selectById(id);
        return AjaxResult.success(userGrowLog);

    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping
    public AjaxResult list(){

        List< UserGrowLog> list = userGrowLogService.selectList(null);
        return AjaxResult.success(list);

    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    public AjaxResult json(@RequestBody UserGrowLogQuery query)
    {
        Page<UserGrowLog> page = new Page<UserGrowLog>(query.getPage(),query.getRows());
        page = userGrowLogService.selectPage(page);
        PageList pageList = new PageList<UserGrowLog>(page.getTotal(),page.getRecords());
        return AjaxResult.success(pageList);
    }



}